/**设置cookie*/ 
export function setCookie(name: string, value: string, day : number = 5) {
	let date = new Date();
	date.setDate(date.getDate() + day);
	document.cookie = name + '=' + value + ';expires=' + date;
}

/**获取cookie*/
export function getCookie(name: string) : string | null {
	let reg = RegExp('(^| )' + name + '=([^;]*)(;|$)');
	let arr = document.cookie.match(reg);
	if (arr) {
		return arr[2];
	} else {
		return null;
	}
} 

/**删除cookie*/
export function removeCookie(name: string) {
	setCookie(name, '1', -1);
}


/**清空cookie*/
export function clearCookie() {
	let keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if (keys) {
		for (let i = keys.length; i--;) {
			document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
		}
	}
} 